package com.acme.bankapp.service.bank;
import com.acme.bankapp.account.NotEnoughFundsException;
import com.acme.bankapp.account.OverDraftLimitExceededException;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.BankException;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.ClientExistsException;

/**
 * TODO: Please add file description for  @fileBankService.java
 * Created: Nov 8, 2013 6:22:37 PM
 */

/**
 * @author Andrey Alekov
 *
 */
public class BankService {
	
	/** 
	 * Add client to bank.
	 * @param bank to change
	 * @param client to add
	 * @throws ClientExistsException if client already exist in bank
	 */
	public void addClient(Bank bank, Client client) throws ClientExistsException{
		bank.addClient(client);
	}
	
	/** 
	 * Print maximum amount to bank.
	 * @param bank to print
	 */
	public void printMaximumAmountToWithdraw(Bank bank){
		bank.printMaximumAmountToWithdraw();
	}

	/** 
	 * Modify client balance
	 * @throws NotEnoughFundsException if not enough balance to withdraw
	 * @throws OverDraftLimitExceededException if not enough balance and overdraft
	 * @throws BankException if unexpected action performed
	 */
	public void modifyBank(Bank bank, Client client, double amount) 
			throws NotEnoughFundsException, OverDraftLimitExceededException, 
			BankException{
		if (amount >= 0d){
			client.getAccount().deposit(amount);
		}
		try {
			client.getAccount().withdraw(amount);
		} catch (OverDraftLimitExceededException e) {
			throw new OverDraftLimitExceededException(client, e.getMessage());
		}
	}
	/** 
	 * Get bank balance
	 * @param 
	 */
	public void printBalance(Bank bank){
		bank.printMaximumAmountToWithdraw();
	}
}
